<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:p="http://primefaces.prime.com.tr/ui"> 

<ui:composition template="/_documento.xhtml">
	<ui:define name="corpo">

		<div id="conteudo">
			<h:form>

				<h2>
					<h:outputText value="Enviar Documento"
						rendered="#{empty enviarDocumentoBean.envia.id}" />
					<h:outputText value="Editar Documento"
						rendered="#{not empty enviarDocumentoBean.envia.id}" />
				</h2>
				
				<p:fieldset legend="Dados do Envio" toggleable="true"><br />

					<h:outputLink value="javascript:void(0)"
						onclick="dlgFunc.show();">
						<h:outputLabel value="Funcionario: " />
					</h:outputLink>
					<p:inputText id="funcionario"
						value="#{enviarDocumentoBean.envia.funcionario.nome}"
						onclick="dlgFunc.show();">
						<f:ajax event="change" />
					</p:inputText>
					<br />

					<h:outputLink value="javascript:void(0)" onclick="dlgSetor1.show();">
						<h:outputLabel value="Setor Origem: " />
					</h:outputLink>
					<p:inputText id="setor1"
						value="#{enviarDocumentoBean.envia.setorOrigem.nome}"
						onclick="dlgSetor1.show();">
						<f:ajax event="change" />
					</p:inputText>
					<br />
					
					<h:outputLink value="javascript:void(0)" onclick="dlgSetor2.show();">
						<h:outputLabel value="Setor Destino: " />
					</h:outputLink>
					<p:inputText id="setor2"
						value="#{enviarDocumentoBean.envia.setorDestino.nome}"
						onclick="dlgSetor2.show();">
						<f:ajax event="change" />
					</p:inputText>
					<br />
					
					<h:outputLink value="javascript:void(0)" onclick="dlgDoc.show();">
						<h:outputLabel value="Documento: " />
					</h:outputLink>
					<p:inputText id="documento"
						value="#{enviarDocumentoBean.envia.documento.numero}"
						onclick="dlgDoc.show();">
						<f:ajax event="change" />
					</p:inputText>
					<br />

					<br />
					<p:commandButton value="Gravar" action="#{enviarDocumentoBean.grava}" ajax="false">
						<f:ajax render="@all" />
					</p:commandButton>

				</p:fieldset>
				
				<p:messages id="msg" />
							
			</h:form>
			
			<p:dialog header="Funcionario" widgetVar="dlgFunc" modal="true"
				width="800" showEffect="explode">
				<h:form id="form1">

					<p:outputPanel id="funcionarios">
						<p:dataTable value="#{funcionarioBean.funcionarios}" var="funcionario"
							paginator="true" rows="5">

							<p:column filterBy="#{funcionario.nome}" filterMatchMode="contains"
								headerText="Funcionario">
								<h:commandLink value="#{funcionario.nome}" onclick="dlgFunc.hide()"
									id="func">
									<f:setPropertyActionListener target="#{enviarDocumentoBean.envia.funcionario}" value="#{funcionario}" />
								</h:commandLink>
							</p:column>	

						</p:dataTable>
					</p:outputPanel>
				</h:form>
			</p:dialog>
			
			<p:dialog header="Setores" widgetVar="dlgSetor2" modal="true"
				width="800" showEffect="explode">
				<h:form id="form2">

					<p:outputPanel id="setores">
						<p:dataTable value="#{setorBean.setores}" var="setor"
							paginator="true" rows="5">

							<p:column filterBy="#{setor.nome}" filterMatchMode="contains"
								headerText="Setor">
								<h:commandLink value="#{setor.nome}" onclick="dlgSetor2.hide()"
									id="setor">
									<f:setPropertyActionListener target="#{enviarDocumentoBean.envia.setorDestino}" value="#{setor}" />
								</h:commandLink>
							</p:column>	
								
							<p:column headerText="Orgão">
								<h:outputText value="#{setor.orgao.nome}" />	
							</p:column>

						</p:dataTable>
					</p:outputPanel>
				</h:form>
			</p:dialog>
			
			<p:dialog header="Setores" widgetVar="dlgSetor1" modal="true"
				width="800" showEffect="explode">
				<h:form id="form3">

					<p:outputPanel id="setores">
						<p:dataTable value="#{setorBean.setores}" var="setor"
							paginator="true" rows="5">

							<p:column filterBy="#{setor.nome}" filterMatchMode="contains"
								headerText="Setor">
								<h:commandLink value="#{setor.nome}" onclick="dlgSetor1.hide()"
									id="setor">
									<f:setPropertyActionListener target="#{enviarDocumentoBean.envia.setorOrigem}" value="#{setor}" />
								</h:commandLink>
							</p:column>	
								
							<p:column headerText="Orgão">
								<h:outputText value="#{setor.orgao.nome}" />	
							</p:column>

						</p:dataTable>
					</p:outputPanel>
				</h:form>
			</p:dialog>
			
			<p:dialog header="Documento" widgetVar="dlgDoc" modal="true"
				width="1000" showEffect="explode">
				<h:form id="form4">

					<p:outputPanel id="documentos">
						<p:dataTable value="#{documentoBean.documentos}" var="documento"
							paginator="true" rows="5">

							<p:column filterBy="#{documento.numero}" filterMatchMode="contains"
								headerText="Documento">
								<h:commandLink value="#{documento.numero}" onclick="dlgDoc.hide()"
									id="doc">
									<f:setPropertyActionListener target="#{enviarDocumentoBean.envia.documento}" value="#{documento}" />
								</h:commandLink>
							</p:column>
							
							<p:column headerText="Tipo">
								<h:outputText value="#{documento.tipo}" />	
							</p:column>
							
							<p:column headerText="Assunto">
								<h:outputText value="#{documento.assunto}" />	
							</p:column>		

						</p:dataTable>
					</p:outputPanel>
				</h:form>
			</p:dialog>
			
		</div>

	</ui:define>
</ui:composition>

</html>
